package com.guinea.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Properties;

public class PropertiesPreferences implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final String GENERATOR_PROPERTIES = "generator.properties";

	private Properties properties = new Properties();

	public PropertiesPreferences() {
		try {
			InputStream resourceAsStream = getInputStream(GENERATOR_PROPERTIES);
			try {
				properties.load(resourceAsStream);
			} finally {
				try {
					resourceAsStream.close();
				} catch (IOException e) {

				}
			}

		} catch (IOException e) {

		}
	}

	private InputStream getInputStream(String preferencesLocation)
			throws IOException {
//		if (preferencesLocation.startsWith("WEB-INF")) {
//			String path = "";
//			String name = StringUtils.substringAfter(preferencesLocation,
//					"WEB-INF/");
//			return new FileInputStream(path + "/" + name);
//		}

		return this.getClass().getResourceAsStream(preferencesLocation);
	}

	public String getPreference(String name) {
		return (String) properties.get(name);
	}

}
